package cn.zkrt.iotms.module.iot.controller;

import cn.zkrt.iotms.comm.R;
import cn.zkrt.iotms.module.iot.dto.DeviceAttributeBDTO;
import cn.zkrt.iotms.module.iot.entity.DeviceAttributeB;
import cn.zkrt.iotms.module.iot.service.DeviceAttributeBService;
import cn.zkrt.iotms.module.iot.validate.ValidationCategory;
import cn.zkrt.iotms.module.iot.vo.DeviceAttributeBVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备属性表(DeviceAttributeB)表控制层
 *
 * @author xulinyu
 * @since 2024-09-29 11:02:35
 */
@Api(tags = "6设备属性")
@RestController
@RequestMapping("deviceAttributeB")
public class DeviceAttributeBController {
    /**
     * 服务对象
     */
    @Resource
    private DeviceAttributeBService deviceAttributeBService;

    /**
     * 分页查询
     *
     * @param typeAttributeName 筛选条件
     * @param page   分页对象
     * @return 查询结果
     */
    @GetMapping
    public R<Page<DeviceAttributeBVO>> queryByPage(Page<DeviceAttributeB> page,String typeAttributeName,String deviceName) {
        return R.data(this.deviceAttributeBService.queryByPage(page,typeAttributeName,deviceName));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R<DeviceAttributeBVO> queryById(@PathVariable("id") String id) {
        return R.data(this.deviceAttributeBService.queryById(id));
    }


    @ApiOperation("根据设备查询设备属性列表")
    @GetMapping("queryByDeviceId")
    public R<List<DeviceAttributeBVO>> queryByDeviceId(@RequestParam String deviceId) {
        return R.data(this.deviceAttributeBService.queryByDeviceId(deviceId));
    }

    /**
     * 新增数据
     *
     * @param dto 实体
     * @return 新增结果
     */
    @PostMapping
    public R<Boolean> add(@Validated @RequestBody DeviceAttributeBDTO dto) {
        return R.data(this.deviceAttributeBService.add(dto));
    }

    /**
     * 编辑数据
     *
     * @param dto 实体
     * @return 编辑结果
     */
    @PutMapping
    public R<Boolean> edit(@Validated({ValidationCategory.Update.class}) @RequestBody DeviceAttributeBDTO dto) {
        return R.data(this.deviceAttributeBService.edit(dto));
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return 删除是否成功
     */
    @DeleteMapping
    public R<Boolean> deleteByIds(@RequestParam("idList") List<Long> idList) {
        return R.data(this.deviceAttributeBService.deleteByIds(idList));
    }

}

